<link type="text/css" rel="stylesheet" href="<?=base_url()?>css/vote.css" />
<script type="text/javascript">
	function sortMe(event_id,sort_value){
		window.location="<?=site_url("vote/voteDetail")?>"+"/"+event_id+"/"+sort_value;
	}
</script>
<div id="border">
  <div id="vote_content">
  <form action="<?=site_url('vote/submitVote')?>" method="post">
  	<table border="0" cellpadding="0" cellspacing="" width="100%">
    	<?php 
    		$cat_desc="";
    		foreach ($items->result_array() as $myitem){
        			$cat_desc=$myitem['vote_item_cat_desc'];
    		}
    	foreach ($events->result_array() as $event){
    	$max_message=(isset($max_error))?$max_error:"";
    	$event_id=$event['event_id'];
    	?>
        <tr>
          <td width="80%" valign="top" colspan="2"><input type="hidden" name="txteventid" id="txteventid" value="<?=$event['event_id']?>">&nbsp;&nbsp;<b><a><?=htmlspecialchars($event['top_name'])?></a></b><p align="justify" style="padding-left: 15px;"><?=htmlspecialchars($event['top_desc'])?></p></td>
        </tr>
        <?php 
        	$byCount="";
        	$byAlpha="";
        	if(isset($sort) && $sort!=1){
        		$byCount="selected";
        	}else if(isset($sort) && $sort==1){
        		$byAlpha="selected";
        	}
    	}
        ?>
        <tr>
        	<td colspan="2">
        		<table border="0" cellpadding="0" cellspacing="0" width="100%">
	         			<tr>
	         				<td colspan="3" align="right" height="30">
	         				Sort by :
	         				<select onchange="javascript:sortMe('<?=$event_id?>',this.value)">
	         					<option value="0" <?=$byCount?>>Count (Highest)</option>
	         					<option value="1" <?=$byAlpha?>><?=htmlspecialchars ($cat_desc)?> (Alphabetic)</option>
	         				</select>
	         				</td>
	         			</tr>  
	         			<?php 
	    					if(isset($Z_USER["user_login"]) && $Z_USER["user_login"]!=""){
	         			?>        
	         			<tr align="center" bgcolor="#DDD" style="font-size: 13px;">
	         				<td width="70%" height="35" style=" border: solid #CCC 1px;"><b><?=htmlspecialchars($cat_desc)?></b></td>
	        				<td align="center"  width="15%" style="border-right: solid #CCC 1px;"><b>Vote</b></td>
	        				<td width="15%" style="border-right: solid #CCC 1px"><b>Count</b></td>
	         			</tr>
	         			<?php 
	    					}else{
	         			?>
	         			<tr align="center" bgcolor="#DDD" style="font-size: 13px;">
	         				<td width="85%" colspan="2" height="35" style="border-left: solid #CCC 1px; border-right: solid #CCC 1px;"><b><?=htmlspecialchars($cat_desc)?></b></td>
	        				<td width="15%" style="border-right: solid #CCC 1px"><b>Count</b></td>
	         			</tr>
	         			<?php 
	    					}
	         			?>
	        	<?php 
	        		$this->load->model('vote_model');
	        		$result=0;
	        		$i=0;
	        		$color="#EEE";
	        		foreach ($items->result_array() as $item){
	        			$i++;
	        			$foundme=false;
	        			$color=($color=="#EEE")?"#FFF":"#EEE";
		        			if($max_message!=""){
		        				for($x=0;$x<count($checkeditems);$x++){
									if($checkeditems[$x]==$item['vote_item_id']){
										$foundme=true;
										break;
									}
								}
		        			}else{
								foreach($curevent->result_array() as $myevent ){
									if($myevent['vote_item_id']==$item['vote_item_id']){
										$foundme=true;
										break;
									}
							}
	        			}
						$checkme=($foundme==true)?"checked":"";
						if(isset($Z_USER["user_login"]) && $Z_USER["user_login"]!=""){
	        	?>
	        		<tr bgcolor="<?=$color?>" style="font-size: 13px;">
	        			<td height="30" style="border-left: solid #CCC 1px; border-right: solid #CCC 1px;">&nbsp;<?=$i.". ".htmlspecialchars($item['vote_item_desc'])?></td>
	        			<td align="center" style="border-right: solid #CCC 1px;"><input type="checkbox" <?=$checkme?> name="items[]" value="<?=$item['vote_item_id']?>"></td>
	        			<td align="center" style="font-size: 12px; border-right: solid #CCC 1px;" ><?=htmlspecialchars($item['vote_count'])?></td>
	        		</tr>
	        	<?php 
						}else{
						
	        	?>
	        		<tr bgcolor="<?=$color?>" style="font-size: 13px;">
	        			<td height="30" colspan="2" style="border-left: solid #CCC 1px; border-right: solid #CCC 1px;">&nbsp;<?=$i.". ".htmlspecialchars($item['vote_item_desc'])?></td>
	        			<td align="center" style="font-size: 12px; border-right: solid #CCC 1px;" ><?=htmlspecialchars($item['vote_count'])?></td>
	        		</tr>
	        	<?php 
						}
					}
	        	?>	
	        		<tr>
	        	       <td colspan="3" style="border: solid #CCC 1px;border-top: solid #CCC 0px;"></td>
	        		</tr>
	        		<tr><td colspan="3">&nbsp;</td></tr>
	        		<?php if($max_message!=""){
        			?>
        			<tr><td colspan="3" height="50"><font color="red"><?=$max_message." ".strtolower($cat_desc)."(s)"?></font></td></tr>
			        <?php 
			        }
			        if(isset($Z_USER["user_login"]) && $Z_USER["user_login"]!=""){
			        ?>
	        		<tr><td colspan="3">&nbsp;</td></tr>
	        		<tr><td colspan="3"><input type="submit" class="kh_button" value="Vote Now"></td></tr>
	        		<?php 
			        }
	        		?>
        		</table>
        	</td>
        </tr>
  	</table>
  	</form>
  </div>
    <div id="right_content">
    	<img src="<?=base_url();?>ads/sony.png" width="322" height="279" />
        <div style="width:302px; height:346px; float:left; background:#F3F3F3; padding:4px; margin-top:6px; font:10px Arial, Helvetica, sans-serif;">
        	 <font color="#333333" size="+1">Most Popular</font>
        	 <div class="read">
             	<b style="font-size:12px">READ</b>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="19" height="52" valign="top"><b style="font:18px Arial, Helvetica, sans-serif; color:#D4D4D4; font-weight:bold">1</b></td>
                    <td width="87%" valign="top"><a href="">UPDATE 1-Los Alamos scurries to protect nuclear lab from fire</a><br />28 Jun 2011</td>
                  </tr>
                </table>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="19" height="52" valign="top"><b style="font:18px Arial, Helvetica, sans-serif; color:#D4D4D4; font-weight:bold">2</b></td>
                    <td width="87%" valign="top"><a href="">UPDATE 1-Los Alamos scurries to protect nuclear lab from fire</a><br />28 Jun 2011</td>
                  </tr>
                </table>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="19" height="52" valign="top"><b style="font:18px Arial, Helvetica, sans-serif; color:#D4D4D4; font-weight:bold">3</b></td>
                    <td width="87%" valign="top"><a href="">UPDATE 1-Los Alamos scurries to protect nuclear lab from fire</a><br />28 Jun 2011</td>
                  </tr>
                </table>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="19" height="52" valign="top"><b style="font:18px Arial, Helvetica, sans-serif; color:#D4D4D4; font-weight:bold">4</b></td>
                    <td width="87%" valign="top"><a href="">UPDATE 1-Los Alamos scurries to protect nuclear lab from fire</a><br />28 Jun 2011</td>
                  </tr>
                </table>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="19" height="52" valign="top"><b style="font:18px Arial, Helvetica, sans-serif; color:#D4D4D4; font-weight:bold">5</b></td>
                    <td width="87%" valign="top"><a href="">UPDATE 1-Los Alamos scurries to protect nuclear lab from fire</a><br />28 Jun 2011</td>
                  </tr>
                </table>                         
             </div>  
        </div>
        <div style="background:#BD2031;margin-top:6px; width:12px; float:right; height:354px;">&nbsp;</div>
	  	<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="<?=base_url();?>ads/ad-01.png" width="162" height="587" /></td>
            <td valign="top">
            	<img src="<?=base_url();?>ads/applemedia1.gif" width="160" height="140" />
                <img src="<?=base_url();?>ads/cellcard.png" width="160" height="210" />
                <img src="<?=base_url();?>ads/wft.png" width="160" height="140" />
            </td>
          </tr>
        </table> 
       </div>

    
</div>